import time

from blls.base_bll import BaseBLL
from dtos.result import Result


cache_dict = {}


class CacheBLL(BaseBLL):
    def create_cache(self, content):
        global cache_dict
        cache_id = str(time.time())
        cache_dict[cache_id] = content
        # print(cache_id, content)
        return Result.success_result(data={"cache_id": cache_id})

    def get_cache(self, cache_id):
        content = cache_dict.get(cache_id, None)
        if content is None:
            return Result.error_result(message=f"no cache record with cache_id {cache_id} found", code=404)
        return Result.success_result(data={"content": content})



